Support for Non-Null Types in Java
نویسندگان
چکیده
We implemented support for non-null types in Java according to the description in [1]. We built our implementation on top of the Polyglot Java compiler as a language extension. Our extension allows programmers to provide annotations specifying whether a variable is allowed to ever take on a null value and provides an augmented type system to enforce these guarantees. Once the separation between non-null and possibly null types is enforced, it is straightforward to modify Java’s typechecking rules to ensure possibly null variables are never used in an unsafe manner, such as dereferencing. In addition to improving software reliability, preventing null-related errors at compile time improves efficiency as superfluous runtime checks can be removed. A complication exists in that Java allows access to partially initialized objects during construction whose fields may not obey their nullity annotations. We address this issue by making special considerations for such “raw” types in a manner similar to the approach of Fähndrich and Leino. Nullity and rawness properties must be manually specified by programmers, but only about 5% of lines require annotations [1].
منابع مشابه
Towards Support for Non-null Types and Non-null-by- default in Java
This paper begins with a survey of current programming language support for non-null types and annotations, with a particular focus on extensions to Java. With the advent of Java 5 annotations, we note a marked increase in the availability of tools that can statically detect potential null dereferences. For such tools to be truly effective, they require that developers annotate declarations wit...
متن کاملNon-null types in an object-oriented language
Non-null types can detect certain null-related errors in object-oriented programs earlier and avoid other such errors altogether. This paper gives a proposal for retrofitting a language like C# or Java with non-null types. It addresses the complications that arise in constructors, where non-null fields may not yet have been initialized.
متن کاملNon-null References by Default in Java: Alleviating the Nullity Annotation Burden
With the advent of Java 5 annotations, we note a marked increase in the availability of tools that can statically detect potential null dereferences. For such tools to be truly effective, they require that developers annotate declarations in their code with nullity modifiers and have annotated API libraries. Unfortunately, it has been our experience in specifying moderately large code bases tha...
متن کاملA Featherweight Calculus for Flow-Sensitive Type Systems in Java
Featherweight Java has been highly successful for reasoning about type systems in Java. However, it is not suited to formalising flow-sensitive type systems. Such systems differ from the norm by allowing variables to have different types at different program points. A large number of problems are naturally expressed in this way. For example, reasoning about non-null types requires retyping a va...
متن کاملJava Bytecode Verification for @NonNull Types
Java’s annotation mechanism allows us to extend its type system with non-null types. However, checking such types cannot be done using the existing bytecode verification algorithm. We extend this algorithm to verify non-null types using a novel technique that identifies aliasing relationships between local variables and stack locations in the JVM. We formalise this for a subset of Java Bytecode...
متن کامل